<?php
include_once 'BaseS.php';
include_once $_SERVER ['DOCUMENT_ROOT'].BASE_PROJECT_PATH.'/library/util/Util.php';
include_once $_SERVER ['DOCUMENT_ROOT'].BASE_PROJECT_PATH.'/library/util/ImgUploads.php';
include_once $_SERVER ['DOCUMENT_ROOT'].BASE_PROJECT_PATH.'/library/util/Regex.php';

class AppImgUploadS extends BaseS {
	
	public function __construct() {
		parent::__construct ();
		parent::setTarget ( $this );
	}
	
	public function uploads(){
		
		$result 		= array("status" => 0, "msg" => "", "photoName" => "");
		
		$phoneType 		= $_POST['phoneType'];
		$phoneVersion 	= $_POST['phoneVersion'];
		$mId 			= $_POST["mId"];
		$token 			= $_POST["token"];
		$type			= $_POST['type'];
		
		$photoPath = "";
		$photoName = $mId.Util::getNowDate("YmdHis");
	
		$img = new ImgUploads();

		if(!Regex::isNumber($phoneType, 1))		{$result["status"] = -3; Util::toEchoJson($result); exit;}
		if(!Regex::isFloat($phoneVersion, 30))	{$result["status"] = -3; Util::toEchoJson($result); exit;}
		if(!$dao->checkToken($mId, $token))		{$result["status"] = -4; Util::toEchoJson($result); exit;}
		
		if($phoneType == 1 && $phoneVersion <= ANDROID_1 ){
			
			if($type == 1){
				$photoPath = $_SERVER ['DOCUMENT_ROOT'].PET_PHOTO_PATH;
			}else if($type == 2){
				$photoPath = $_SERVER ['DOCUMENT_ROOT'].BM_PHOTO_PATH;
			}else{
				$result["status"] = -3;
				Util::toEchoJson($result);
				exit;
			}
					
			$ret = $img->ImgUpload($photoPath, $photoName);
					
			if($ret){
				$result["status"] = 1;
				$result["photoName"] = $ret;
				Util::toEchoJson($result);
				exit;
			}else{
				$result["status"] = -3;
				Util::toEchoJson($result);
				exit;
			}
		}
	}
	
	public function getPhotoPath(){
		
		$result = array();
		$phoneType 		= $_POST['phoneType'];
		$phoneVersion 	= $_POST['phoneVersion'];
		
		if($phoneType == 1 && $phoneVersion <= ANDROID_1 ){
			
			$result = array(
					"petPath" => PET_PHOTO_PATH,
					"newsPath" => NEWS_PHOTO_PATH,
					"BMPath" => BM_PHOTO_PATH
			);
			
		}
		
		Util::toEchoJson($result);
		exit;
	}
	
}

if (isset($_GET["action"])) {
	$service = new AppImgUploadS ();
	$service->__call ( $_GET["action"], null );
} 
?>